/*
   Copyright (c) 2010-2014, AMI RESEARCH GROUP <lalvarez@dis.ulpgc.es>
   License : CC Creative Commons "Attribution-NonCommercial-ShareAlike"
   see http://creativecommons.org/licenses/by-nc-sa/3.0/es/deed.en
 */


#ifndef AMI_DLL_H
  #define AMI_DLL_H
#endif

/**
 * \file point2d.h
 * \brief point2d class  definition
 * \author Luis Alvarez \n \n
*/
#ifndef POINT2D_H
#define POINT2D_H
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

namespace ami
{

/**
 * \class  point2d
 * \brief class  to store 2D points and basic methods
 * \author Luis Alvarez
 */
template < class  T >
class AMI_DLL_H point2d {

  public :
  T x /** point x coordinate */;
  T y /** point y coordinate */;
  point2d():x( (T) 0), y( (T) 0){};
  ~point2d(){};
  point2d(const T xx , const T yy){x=xx; y=yy;}
  point2d(const T scalar){x=y=scalar;}
  point2d & operator=(const point2d &p){ x=p.x; y=p.y; return *this;}
  point2d & operator=(const T scalar){ x=scalar; y=scalar; return *this;}
  point2d (const point2d<T> &p){x=p.x; y=p.y;}
  point2d operator+(const point2d &p)const {return point2d(x+p.x,y+p.y);}
  point2d operator-(const point2d &p)const {return point2d(x-p.x,y-p.y);}
  point2d operator*(const T &a)const {return point2d(a*x,a*y);}
  double operator*(const point2d &p)const {return ( (double) x*p.x+y*p.y);}
  inline T norm(){T paso=x*x+y*y; return(paso>0.?sqrtf((float) paso):0.);}
  inline T norm2(){ return(x*x+y*y);}
  void print(){ std::cout << "point2d : (" << x << "," << y << ")" <<
                std::endl;}
  bool operator!=(const T scalar) const {return(x!=scalar && y!=scalar);}
};

}
#endif
